package com.cskaoyan.utils;

import java.util.Random;

/**
 * @PROJECT_NAME: market_34th
 * @DESCRIPTION:
 * @Author: qiu
 * @DATE: 2021/10/19 15:30
 */
public class RandomUtil {

    public static String GetRandomString(int len) {

        String[] baseString={"0","1","2","3",
                "4","5","6","7","8","9",
                "a","b","c","d","e",
                "f","g","h","i","j",
                "k","l","m","n","o",
                "p","q","r","s","t",
                "u","v","w","x","y",
                "z","A","B","C","D",
                "E","F","G","H","I",
                "J","K","L","M","N",
                "O","P","Q","R","S",
                "T","U","V","W","X","Y","Z"};

        return getResultString(len, baseString);
    }

    public static String getRandomNumber(int len){
        String[] baseString={"0","1","2","3",
                "4","5","6","7","8","9"};
        return getResultString(len, baseString);
    }

    private static String getResultString(int len, String[] baseString) {
        Random random = new Random();
        int length = baseString.length;
        String randomString = "";
        for (int i = 0; i < length; i++) {
            randomString += baseString[random.nextInt(length)];
        }
        random = new Random(System.currentTimeMillis());
        String resultStr = "";
        for (int i = 0; i < len; i++) {
            resultStr += randomString.charAt(random.nextInt(randomString.length() - 1));
        }
        return resultStr;
    }
}
